(function () {
    var EVENT_CLICK = Laya.Event.CLICK;
    var io = ppt.io;

    function roleUp(call) {
        roleUp.super(this);
        this.skillType = null;
        this.data = null;
        this.callback = call;
        this.init();
    }
    Laya.class(roleUp, "Com.Role.Up", ui.Role.RoleUpUI);
    var _proto = roleUp.prototype;

    _proto.init = function () {
        this.bindEvent();
    }
    _proto.bindEvent = function () {
        this.upgradeBtn.on(Laya.Event.CLICK, this, function () {
            io.emit({ 'cmd': 'role::skillUp', params: { 'roleId': this.data.roleId, 'skillType': this.data.skill[this.skillType].skillType } });
        });
    }
    //技能升级结果更新
    _proto.upgradeData = function (data) {
        if (data.code) {
            var config = {
                msg: data.msg,
                close: true,
                btn: {
                    btnCancel: false
                }
            }

            switch (data.code) {
                case 303:
                    config.btn = {
                        btnCancel: {
                            skin: "challenge",
                            click: function () {
                                io.emit({ cmd: 'pve::wait', params: { type: 6 } });
                            }
                        },
                        btnConfirm: {
                            skin: "race",
                            click: function () {
                                ppt.director.runScene(new Scene.Matching());
                            }
                        }
                    }
                    break;
                default:
                    config.btn.btnConfirm = {
                        skin: "confirm"
                    }
            }

            ppt.director.popScene(new Alert.Public(config));
            return;
        }
        io.emit({ 'cmd': 'game::enter', params: {} });
        if (data.skillInfo.cd) {
            this.skillsCd.text = "CD:" + data.skillInfo.cd + "s";
        }
        if (data.skillInfo.lv) {
            this.skillsCd.text = "等级:" + data.skillInfo.lv + '/' + data.skillInfo.maxlv;
        }
        this.upgradeNum.text = data.skillInfo.lvlup;
        this.skillsTxt.text = data.skillInfo.detail;
        if(data.skillInfo.lv == data.skillInfo.maxlv){
            this.upgradeBtn.visible = false;
        }
        this.callback();
    }
    _proto.upData = function (data, type) {
        this.data = data;
        this.skillType = type;
        if (type == 0 || type == 3 || type == 4) {
            this.upgradeBtn.visible = false;
        }
        if (type == 1) {
            if (this.data.status == 0 || this.data.status == 1) {
                this.upgradeBtn.visible = true;
                this.upgradeNum.text = this.data.skill[type].lvlup;

            } else {
                this.upgradeBtn.visible = false;
            }


        }
        if (type == 2) {

            if (this.data.status == 0 || this.data.status == 1) {
                this.upgradeBtn.visible = true;
                this.upgradeNum.text = this.data.skill[type].lvlup;
            } else {
                this.upgradeBtn.visible = false;
            }


        }
        if (this.data.skill[type].cd > 0) {
            this.skillsCd.text = "CD:" + this.data.skill[type].cd + "s";
        }
        if (this.data.skill[type].lv > 0) {
            this.skillsCd.text = "等级:" + this.data.skill[type].lv + '/' + this.data.skill[type].maxlv;
        }
        if (this.data.skill[type].cd == 0 && this.data.skill[type].maxlv == 0) {
            this.skillsCd.text = '';
        }
        if (this.data.skill[type].type == 1) {
            this.skillsChange.text = '主动技能';
        }
        else if (this.data.skill[type].type == 2) {
            this.skillsChange.text = '进阶技能';
        }
        else if (this.data.skill[type].type == 3) {
            this.skillsChange.text = '天赋技能';
        }
        else if (this.data.skill[type].type == 4) {
            this.skillsChange.text = '觉醒技能';
        }
        this.sanjiao.x = 200 + 90 * type;
        this.skillsUnlock.text = '星级' + (type + 1) + '级解锁';
        this.skillsName.text = this.data.skill[type].name;
        this.skillsTxt.text = this.data.skill[type].detail;
    }
})();